package me.may.money.listener;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

import me.may.money.api.MoneyAPI;
import me.may.money.dao.CacheDao;

public class PlayerJoinListener implements Listener {
	
	@EventHandler(priority = EventPriority.HIGH)
	public void onJoin(PlayerJoinEvent e) {
		Player player = e.getPlayer();
		// 因为应用实现层已做过判断,这里可以直接执行该方法
		MoneyAPI.initialPlayerAccount(player.getName());
		// 载入缓存
		CacheDao.putPlayerData(e.getPlayer().getName(), String.valueOf(MoneyAPI.getPlayerMoney(e.getPlayer().getName())));
	}
}
